import 'package:dio/dio.dart';
import 'package:erp/data/http/dio_client.dart';
import 'package:erp/data/http/interceptors/request_interceptor.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart' as DotEnv;
import 'package:flutter_user_agentx/flutter_user_agent.dart';
import 'package:get/get.dart';

class DioService extends GetxService {
  Future<DioClient> init([BaseOptions? options]) async {
    await DotEnv.load();
    String userAgent = await FlutterUserAgent.getPropertyAsync('userAgent');
    BaseOptions options = BaseOptions(
      baseUrl: DotEnv.env['BASE_URL'] ?? "",
      headers: {"User-Agent": userAgent},
      contentType: 'application/json',
      connectTimeout: 30000,
      receiveTimeout: 30000,
      sendTimeout: 30000,
    );
    Dio dio = Dio(options);
    dio.interceptors.addAll([
      // PrettyDioLogger(),
      RequestInterceptor(),
    ]);
    return DioClient(dio: dio);
  }
}
